package com.yx.sp_mybatis.service.impl;

import com.yx.sp_mybatis.dao.UserDao;
import com.yx.sp_mybatis.entity.User;
import com.yx.sp_mybatis.service.UserService;
import com.yx.sp_mybatis.util.model.Pager;
import com.yx.sp_mybatis.vo.UserQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 姚天下
 * @version 1.0
 * @description: TODO
 * @date 2021/8/30 13:49
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;
    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public User findById(Long id) {
        return userDao.findById(id);
    }

    @Override
    public Pager<User> findByPager1(int page, int size) {
        Map<String,Object> params = new HashMap<>();
        params.put("page",(page-1)*size);
        params.put("size",size);
        Pager<User>  pager = new Pager<User>();
        final List<User> users = userDao.findByPager1(params);
        pager.setRows(users);
        pager.setTotal(userDao.count1());
        return pager;
    }


    @Override
    public User findByUsernameAndPassword1(String username, String password) {
        return userDao.findByUsernameAndPassword1(username,password);
    }

    @Override
    public User findByUsernameAndPassword2(String username, String password) {
        return userDao.findByUsernameAndPassword2(username,password);
    }

    @Override
    public User findByUsernameAndPassword3(Map<String, Object> params) {
        return userDao.findByUsernameAndPassword3(params);
    }

    @Override
    public User findByUsernameAndPassword4(UserQueryVo vo) {
        return userDao.findByUsernameAndPassword4(vo);
    }

    @Override
    public void save1(User user) {
        userDao.save1(user);
    }

    @Override
    public void save2(User user) {
        userDao.save2(user);
    }
}
